package com.hibuy.pc.controller;

import com.hibuy.pc.model.shiro.Role;
import com.hibuy.pc.service.shiro.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by admin on 2017/12/28.
 */
@Controller
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

//    @RequestMapping(value = "list",method = RequestMethod.GET)
//    public String toRole (){
//        return "role/list";
//    }
//
//    @RequestMapping(value = "list",method = RequestMethod.POST)
//    @ResponseBody
//    public List<Role> getRoles (){
//        return  roleService.getRoles();
//    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public String getRoles (HttpServletRequest request){
        request.setAttribute("roles",roleService.getRoles());
        return "role/list";
    }

    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String addRoles (HttpServletRequest request){

        String name = request.getParameter("name");
        String type = request.getParameter("type");

        String[] permissionIds = request.getParameterValues("permissionIds");
        Role role = new Role();
        role.setName(name);
        role.setType(type);
        roleService.addRoles(role,permissionIds);
        return  "";
    }



}
